<?php

class dbManagerController extends controllerBase {
	protected $mode = AETHER_CLI;
	protected $view = false;

	function install($tables = null, $backupDir = null) {
		if($tables===null) {
			$args = $this->getParams('args');
			if(isset($args['b'][0])) {
				$backupDir = $args['b'][0];
			}
			$tables = $this->h->db->getTableArg($this->getParam('id'), $args);
		}
		if(!file_exists('app/backups/'.$backupDir)) {
			die('Backup directory does not exist');
		}
		$this->h->dbTables->install
			

class dbController extends controllerBase {
	protected $mode = AETHER_CLI;
	protected $view = false;
	protected $helpers = array('db');
	
	function install() {
		echo 'Installing tables... ';
		$args = $this->getParam('args');
		if(isset($args['b'][0])) {
			$backupDir = $args['b'][0];
			if(!file_exists('app/backups/'.$backupDir)) {
				die('Backup directory does not exist');
			}
		} else {
			$backupDir = null;
		}
		$this->h->db->install($this->h->db->getTableArg($this->getParam('id'), $args), $backupDir);
		echo 'Done.';
	}
	
	function reinstall() {
		$this->uninstall();
		echo NL;
		$this->install();
	}
	
	function uninstall() {
		echo 'Uninstalling tables... ';
		$this->h->db->uninstall($this->h->db->getTableArg($this->getParam('id'), $this->getParam('args')));
		echo 'Done.';
	}

	function backup() {
		echo 'Backing up tables... (This may take a while) ';
		$this->h->db->backup($this->h->db->getTableArg($this->getParam('id'), $this->getParam('args')));
		echo 'Done.';
	}
}

?>
